import { createWebHashHistory, createRouter } from "vue-router";
import type { Router } from "vue-router";

interface Behavior {
   top: number;
   left: number;
}

const router: Router = createRouter({
   history: createWebHashHistory(),
   routes: [
      {
         path: "/",
         name: "layout",
         component: () => import("@/layout/layout.vue"),
         children: [
            {
               path: "",
               name: "home",
               component: () => import("@/views/home/home.vue"),
            },
            {
               path: "/subcategory/:id",
               name: "subcategory",
               component: () => import("@/views/subCategory/subCategory.vue"),
            },
            {
               path: "/category/:id",
               name: "category",
               component: () => import("@/views/category/category.vue"),
            },
            {
               path: "/detail/:id",
               name: "detail",
               component: () => import("@/views/detail/detail.vue"),
            },
            {
               path: "/shopcart",
               name: "shopcart",
               component: () => import("@/views/shopCart/shopCart.vue"),
            },
            {
               path: "/member/checkout",
               name: "checkout",
               component: () => import("@/views/member/pay/checkout.vue"),
            },
            {
               path: "/member/pay",
               name: "pay",
               component: () => import("@/views/member/pay/pay.vue"),
            },
            {
               path: "/pay/callback",
               name: "paycallback",
               component: () => import("@/views/member/pay/callback.vue"),
            },
         ],
      },
      {
         path: "/login",
         name: "login",
         component: () => import("@/views/login/login.vue"),
      },
      {
         path: "/login/callback",
         name: "callback",
         component: () => import("@/views/login/components/callback/callback.vue"),
      },
      {
         path: "/404",
         name: "404",
         component: () => import("@/views/404.vue"),
      },
      {
         path: "/:pathMatch(.*)",
         redirect: "/404",
      },
   ],
   scrollBehavior(): Behavior {
      return { top: 0, left: 0 };
   },
});

export default router;
